﻿
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class testmysql : Form
    {
        public testmysql()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;user=root;database=studentclubmisdb;port=3306;password=123456";

            // 创建一个新的连接  
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                // 打开连接  
                conn.Open();
                Console.WriteLine("连接成功");
                MessageBox.Show("数据库连接成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine("连接失败: " + ex.Message);

            }
            conn.Close();
            MessageBox.Show("关闭数据库成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    }

